import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from "@/views/Layout";
import Login from "@/views/Login";
import UserRegister from "@/views/user/UserRegister";

Vue.use(VueRouter);

const routes = [
	{
		path: '/login',
		name: 'login',
		meta: {
			requireAuth: false,
			title: '登陆'
		},
		component: Login
	},
	{
		path: "/register",
		name: 'userRegister',
		component: UserRegister,
		meta: {
			requireAuth: false,
			title: '注册'
		},
		// component: () => import('../views/user/UserRegister')
	},
	{
		path: '/',
		name: 'layout',
		component: () => import('@/views/Layout'),
		meta: {
			title: '知识库系统'
		},
		children: [
			{
				path: '/console',
				name: 'console',
				component: () => import('../views/Console'),
				meta: {
					title: '首页'
				}
			},

			{
				path: '/knowledge-center',
				name: 'knowledgeCenter',
				component: () => import('../views/knowledge/KnowledgeCenter'),
			},

			{
				path: '/user/profile',
				name: 'profile',
				component: () => import('../views/user/UserDetail'),
				meta: {
					title: '用户信息'
				}
			}
		]
	},
	{
		path: '/admin',
		name: 'admin',
		component: () => import('@/views/admin/Admin'),
		meta: {
			title: '后台管理平台'
		}
	}
];

const router = new VueRouter({
	routes
});

router.afterEach((to, from) => {
	document.title = to.meta.title;
});

export default router
